package com.xd.pre.modules.tpshop.controller;

import com.xd.pre.common.utils.Result;
import com.xd.pre.modules.tpshop.service.ITpGoodsAttributeService;
import com.xd.pre.modules.tpshop.virtuaBean.Attribute_virtual;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author lx
 * @since 2020-06-03
 */
@RestController
@RequestMapping("/TpGoodsAttribute")
public class TpGoodsAttributeController {


    @Autowired
    private ITpGoodsAttributeService ga_biz;

    //【1,推荐【2】】 http://localhost:8080/tpshop_server/TpGoodsAttribute/find_SPProductAttribute_list_byGoodsId9?goodsId=1			// 测试已通过！！
    @RequestMapping(value = "/find_SPProductAttribute_list_byGoodsId9", method = RequestMethod.GET)

    public Result find_SPProductAttribute_list_byGoodsId9(HttpServletRequest request) { //

        Result result = new Result();

        System.out.println("测试--1-request.getParameter(goodsId)-->: " + request.getParameter("goodsId")); //

        String goodsId = request.getParameter("goodsId"); //

        List sp_list = null;

        if (null != goodsId && !"".equals(goodsId)) {
            sp_list = new ArrayList();
            sp_list = ga_biz.find_SPProductAttribute_list_byGoodsId(Integer.parseInt(goodsId));
            result.setData(sp_list);
        } else {
//					System.out.println("测试--4-user = null -->: "); //
            result.setData("goodsId为null");
        }

        return result;
    }

    //【2】 http://localhost:8080/tpshop_server/TpGoodsAttribute/find_SPProductAttribute_list_byGoodsId?goodsId=1			// 测试已通过！！
    @RequestMapping(value = "/find_SPProductAttribute_list_byGoodsId", method = RequestMethod.GET)

    public Result find_SPProductAttribute_list_byGoodsId(HttpServletRequest request) { //

        Result result = new Result();

        System.out.println("测试--1-request.getParameter(goodsId)-->: " + request.getParameter("goodsId")); //

        String goodsId = request.getParameter("goodsId"); //

        if (null != goodsId && !"".equals(goodsId)) {
            List<Attribute_virtual> av_list = ga_biz.Attribute2Virtual(goodsId);

            result.setData(av_list);
        }
//				else{
////						System.out.println("测试--4-user = null -->: "); //
//					result.setData("goodsId为null");
//				}

        return result;
    }


}

